//
//  GuideViewController.m
//  AFNetworking
//
//  Created by admin on 2020/4/21.
//

#import "GuideViewController.h"
#import "DefualCollectionViewCell.h"

@interface GuideViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UICollectionView * collectionView;

@property (nonatomic, strong) NSMutableArray * datalist;

@property (nonatomic, strong)UICollectionViewFlowLayout * flowLayout;

@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configUI];
    
}
-(void)configUI{
    self.view.backgroundColor = COLORPRIMARY;
    [self.navigationController setNavigationBarHidden:YES];
    [self.view addSubview:self.collectionView];
    [self.view addSubview:self.closeBtn];
}

-(UIButton *)closeBtn{
    if (!_closeBtn) {
        _closeBtn = [UIButton new];
        [_closeBtn setTitle:@"跳过" forState:UIControlStateNormal];
        [_closeBtn.titleLabel setFont:FONT_SYS12];
        [_closeBtn ug_borderColor:COLORPRIMARY width:1];
        [_closeBtn ug_radius:22];
        [_closeBtn ug_shadowColor:COLORINFO width:4];
    }
    return _closeBtn;
}
-(NSMutableArray *)datalist{
    if (!_datalist) {
        _datalist = [@[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"] mutableCopy];
    }
    return _datalist;
}

-(UICollectionView *)collectionView{
    if (!_collectionView) {
        
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.flowLayout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.pagingEnabled = YES;
        [_collectionView registerClass:[DefualCollectionViewCell class] forCellWithReuseIdentifier:@"DefualCollectionViewCell"];
    }
    return _collectionView;
}
-(UICollectionViewFlowLayout *)flowLayout{
    if (!_flowLayout) {
        _flowLayout = [UICollectionViewFlowLayout new];
        _flowLayout.minimumLineSpacing = 0.0;
        _flowLayout.minimumInteritemSpacing = 0.0;
        _flowLayout.headerReferenceSize = CGSizeZero;
        
        _flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    }
    return _flowLayout;
}

#pragma mark UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.datalist.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    DefualCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DefualCollectionViewCell" forIndexPath:indexPath];
    cell.backgroundColor = UIColor.ug_random;
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    return CGSizeMake(KWidth, KHeight);
    
}
-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view);
        make.right.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view);
    }];
    [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.view).mas_offset(-10);
        make.top.mas_equalTo(self.view).mas_offset(10+KSAFE_Top);
        make.size.mas_equalTo(CGSizeMake(44, 44));
    }];
}

@end
